//
//  EFengOrganizationCell.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/2/16.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengOrganizationCell.h"
#import "WZTabBarButton.h"
#import "CContactModel.h"
#import "CDepartmentModel.h"
#import "UIImageView+WebCache.h"
#import "CXmppRequestMgr.h"


@interface EFengOrganizationCell ()

WeakProperty UIImageView *iconImageView;
WeakProperty UILabel *nameLabel;
//WeakProperty WZTabBarButton *button;

@end

@implementation EFengOrganizationCell

+ (instancetype)organizationCellWithCollectionview:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath
{
    static NSString *organizationId = @"organizationCell";
    EFengOrganizationCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:organizationId forIndexPath:indexPath];
    cell.cellIndexPath = indexPath;
    return cell;
}

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
//        WZTabBarButton *button = [WZTabBarButton buttonWithType:UIButtonTypeCustom];
//        //        button.adjustsImageWhenHighlighted = NO;
//        [button setTitleColor:BlackColor forState:UIControlStateNormal];
//        button.titleLabel.font = [UIFont systemFontOfSize:12.0];
//        button.contentEdgeInsets = UIEdgeInsetsMake(10.0f, 0, 0, 0);
//        button.userInteractionEnabled = NO;
//        [self.contentView addSubview:button];
//        button.backgroundColor = RedColor;
//        self.button = button;
        
        UIImageView *img = [[UIImageView alloc] init];
        img.layer.cornerRadius = 3.0f;
        img.layer.masksToBounds = YES;
        [self.contentView addSubview:img];
        self.iconImageView = img;
    
        UILabel *label = [[UILabel alloc] init];
        label.textColor = RGBCOLORWITH16COLOR(0x323232);
        label.textAlignment = UITextAlignmentCenter;
        label.font = Font12;
        [self.contentView addSubview:label];
        self.nameLabel = label;
        
    }
    return self;
}

- (void)setOrganization:(id)organization
{
    _organization = organization;
    if ([organization isKindOfClass:[CContactModel class]]) {
        CContactModel *contactModel = (CContactModel *)organization;
         [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:contactModel.UserID]] placeholderImage:[UIImage imageNamed:@"80-80"]];
        if ([contactModel.IsAvailable isEqualToString:@"在线"]) {
            
            self.iconImageView.alpha = 1.0f;
//            if ([contactModel.SEX isEqualToString:@"女"]) {
//                    
//                [self.button setImage:[UIImage imageNamed:@"icon-woman"] forState:UIControlStateNormal];
//            } else {
//                [self.button setImage:[UIImage imageNamed:@"icon-man"] forState:UIControlStateNormal];
//            }
            
        } else {
            
            self.iconImageView.alpha = 0.4f;
//            if ([contactModel.SEX isEqualToString:@"女"]) {
//                    
//                [self.button setImage:[UIImage imageNamed:@"icon-womanOffline"] forState:UIControlStateNormal];
//            } else {
//                [self.button setImage:[UIImage imageNamed:@"icon-manOffline"] forState:UIControlStateNormal];
//            }
            
        }
        self.nameLabel.text = contactModel.UserName;
    } else if ([organization isKindOfClass:[CDepartmentModel class]]) {
        CDepartmentModel *dep = (CDepartmentModel *)organization;
        [self.iconImageView  setImage:[UIImage imageNamed:@"icon-Group"]];
        self.iconImageView.alpha = 1.0f;

    
        [self.nameLabel setText:dep.DepartName];

    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
//    self.button.frame = self.bounds;
    self.iconImageView.frame = CGRectMake((self.width - 40.0f * HARDWARE_SCREEN_WIDTH / 320.0f) / 2.0f, 5.0f, 40.0f * HARDWARE_SCREEN_WIDTH / 320.0f, 40.0f * HARDWARE_SCREEN_WIDTH / 320.0f);
    self.nameLabel.frame = CGRectMake(0, CGRectGetMaxY(self.iconImageView.frame), self.width, self.height - CGRectGetMaxY(self.iconImageView.frame));
    
}

@end
